/**
 * 
 */
package net.microlinktech.testing.ui.celleditor;

import java.awt.event.MouseEvent;
import java.util.EventObject;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
 * @author zhangqing
 *
 */
public class HexTextFieldEditor extends AbstractCellEditor implements TableCellEditor {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	final HexTextField textField;

	public HexTextFieldEditor() {
		textField = new HexTextField();
	}
	
	public HexTextFieldEditor(int maxLength) {
		textField = new HexTextField(maxLength);
	}

	public java.awt.Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
			int row, int column) {
		textField.setText((String)value);
		return textField;
	}

	public boolean isCellEditable(EventObject evt) {
		if (evt instanceof MouseEvent) {
			return ((MouseEvent) evt).getClickCount() >= 2;
		}
		return true;
	}

	public Object getCellEditorValue() {
		return textField.getText();
	}
}
